<template>
  <div class="consult">
    <h2 class="title">
      课程咨询
    </h2>
    <ul class="consult-list">
      <li v-for="(item,index) in consultList" :key="index" class="consult-item">
        <div class="like-box">
          <i class="iconfont like">&#xe60c;</i>
          <p class="number">
            {{ item.like }}
          </p>
        </div>
        <div class="content" @click="toCourse(item.courseId)">
          <h3 class="title-box">
            <span class="title ellipsis">{{ item.content }}</span>
            <span class="time">{{ item.gmtCreate }}</span>
          </h3>
          <p class="answer" v-if="item.reply == null">
            {{ `系统消息：讲师还未回答~` }}
          </p>
          <p class="answer" v-else>
            {{ item.reply }}
          </p>
          <p class="from">
            来自：{{ item.courseName }}
          </p>
        </div>
      </li>
    </ul>

    <div v-if="consultList.length === 0 || consultList === null" class="list-empty">
      <p>暂无咨询记录</p>
    </div>

    <!-- 分页 -->
    <el-pagination
            :current-page="page"
            :page-size="limit"
            :total="total"
            style="padding: 30px 0; text-align: center;"
            layout="total, prev, pager, next, jumper"
            @current-change="getConsultList"
    />
  </div>
</template>
<script>
import { getOrderConsultPageList } from '@/api/consult';
import { mapGetters } from 'vuex';

export default {
  data () {
    return {
      total: 0, // 总记录数
      page: 1, // 页码
      limit: 10, // 每页记录数
      consultList: [] // 咨询数据
    }
  },
  created () {
    this.getConsultList()
  },
  methods: {
    // 获取用户咨询数据
    getConsultList () {
      getOrderConsultPageList(this.page,this.limit,this.userId).then(result => {
        let { code, data } = result
        if (code === 20000) {
          this.consultList = data.rows
          this.total = data.total
        }
      })
    },
    //新窗口至课程详情
    toCourse(courseId){
      let url = this.$router.resolve({
        path: '/course/'+courseId,
      });
      window.open(url.href, '_blank')
    }
  },
  computed: {
    ...mapGetters({
      'userId': 'id'
    })
  },
}
</script>

<style lang="stylus" scoped>
  @import '~assets/stylus/mixin.styl';
  .consult
    .title
      margin-bottom: 24px
      font-size: 16px;
      color: #07111b;
      font-weight: 700;
      line-height: 32px;
    .consult-list
      .consult-item
        display: flex;
        align-items: flex-start;
        margin-bottom: 20px;
        padding: 32px;
        background-color: #fff;
        box-shadow: 0 4px 8px 2px rgba(0,0,0,0.1);
        border-radius: 12px;
        .like-box
          margin-right: 16px;
          width: 36px;
          .iconfont
            display: block;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            text-align:center;
            line-height: 36px;
            color: #93999f;
            background-color: #f3f5f7;
            &.like
              background-color: rgba(240,20,20,.1);
              color: #f01414;
          .number
            text-align: center;
            font-size: 12px;
            color: #93999f;
            line-height: 24px;
        .content
          flex: 1;
          cursor pointer;
          .title-box
            margin-bottom: 8px;
            color: #07111b;
            font-size: 16px;
            line-height: 32px;
            .title
              font-weight: 400;
            .time
              float: right;
              font-size: 14px;
              color: #93999f;
          .answer
            margin-bottom: 12px;
            color:#4d555d;
            font-size: 14px;
            line-height: 24px;
            multline-ellipsis(3)
          .from
            font-size: 14px;
            color: #93999f;
            line-height: 24px;
  .list-empty
    padding: 10px 0;
    text-align: center;
</style>
